package com.two.inventory.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.two.inventory.service.InventoryService;
import com.two.inventory.service.impl.InventoryServiceImpl;
@WebServlet("/addInventory.do")
public class AddInventoryServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("UTF-8");
		String id = req.getParameter("id");
		String inventoryname = req.getParameter("inventoryname");
		String price = req.getParameter("price");
		String number = req.getParameter("number");
		InventoryService service = new InventoryServiceImpl();
		boolean result = service.addInventory(id, inventoryname, price, number);
		System.out.println("添加结果：" + result);
		req.getRequestDispatcher("view/inventoryindex/kcadd.html").forward(req, resp);
	}
	

}